package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.mapper.BusinessMapper;
import com.example.mybatisplus.model.domain.Business;
import com.example.mybatisplus.model.domain.BusinessRecommendations;
import com.example.mybatisplus.mapper.BusinessRecommendationsMapper;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.service.BusinessRecommendationsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lxp
 * @since 2025-03-12
 */
@Service
public class BusinessRecommendationsServiceImpl extends ServiceImpl<BusinessRecommendationsMapper, BusinessRecommendations> implements BusinessRecommendationsService {
    @Autowired
    private BusinessRecommendationsMapper businessRecommendationsMapper;

    @Override
    public Page<BusinessRecommendations> pageList(BusinessRecommendations businessRecommendations, PageDTO dto) {
        Page<BusinessRecommendations> page = new Page<>(dto.getPageNo(), dto.getPageSize());
        QueryWrapper<BusinessRecommendations> wrapper = new QueryWrapper<>();
        // 排序逻辑
        List<BusinessRecommendations> list = businessRecommendationsMapper.findHighIndexBusiness();
        int total = list.size();
        int start = (int) ((page.getCurrent() - 1) * page.getSize());
        int end = Math.min(start + (int) page.getSize(), total);
        List<BusinessRecommendations> pageList = list.subList(start, end);
        page.setTotal(total);
        page.setRecords(pageList);

        return page;
    }
}
